/******************************************************************************
	@Author: Manh Cuong
  @CreatDate: 29/06/2012
	@Application: uart platform
*******************************************************************************/
#include "stdio.h"
#include "stm32f10x.h"

#define CONSOLE    USART1

typedef enum{
	eSerCOM1=0,
	eSerCOM2,
	eSerCOM3,
	eSerCOM4,
	eSerCOM5
}serCOM;

typedef enum{
	sbaud_4800,
	sbaud_9600,
	sbaud_19200,
	sbaud_38400,
	sbaud_57600,
	sbaud_115200
}eBaudrate;


#define COM1RxPIN                              GPIO_Pin_10
#define COM1RxPORT                             GPIOA
#define COM1RxCLK                              RCC_APB2Periph_GPIOA

#define COM1TxPIN                              GPIO_Pin_9
#define COM1TxPORT                             GPIOA
#define COM1TxCLK                              RCC_APB2Periph_GPIOA

#define COM2RxPIN                              GPIO_Pin_3
#define COM2RxPORT                             GPIOA
#define COM2RxCLK                              RCC_APB2Periph_GPIOA

#define COM2TxPIN                              GPIO_Pin_2
#define COM2TxPORT                             GPIOA
#define COM2TxCLK                              RCC_APB2Periph_GPIOA

#define COM3RxPIN                              GPIO_Pin_11
#define COM3RxPORT                             GPIOB
#define COM3RxCLK                              RCC_APB2Periph_GPIOB

#define COM3TxPIN                              GPIO_Pin_10
#define COM3TxPORT                             GPIOB
#define COM3TxCLK                              RCC_APB2Periph_GPIOB

#define COM4RxPIN                              GPIO_Pin_11
#define COM4RxPORT                             GPIOC
#define COM4RxCLK                              RCC_APB2Periph_GPIOC

#define COM4TxPIN                              GPIO_Pin_10
#define COM4TxPORT                             GPIOC
#define COM4TxCLK                              RCC_APB2Periph_GPIOC

#define COM5RxPIN                              GPIO_Pin_2
#define COM5RxPORT                             GPIOD
#define COM5RxCLK                              RCC_APB2Periph_GPIOD

#define COM5TxPIN                              GPIO_Pin_12
#define COM5TxPORT                             GPIOC
#define COM5TxCLK                              RCC_APB2Periph_GPIOC


#define COM1                                   USART1
#define COM2                                   USART2
#define COM3                                   USART3
#define COM4                                   UART4
#define COM5                                   UART5

#define COM1CLK                                RCC_APB2Periph_USART1 
#define COM2CLK                                RCC_APB1Periph_USART2 
#define COM3CLK                                RCC_APB1Periph_USART3 
#define COM4CLK                                RCC_APB1Periph_UART4 
#define COM5CLK                                RCC_APB1Periph_UART5 

#define COM1IRQChannel                         USART1_IRQn
#define COM2IRQChannel                         USART2_IRQn
#define COM3IRQChannel                         USART3_IRQn
#define COM4IRQChannel                         UART4_IRQn
#define COM5IRQChannel                         UART5_IRQn

int fputc(int ch, FILE *f);                           /*retarget for printf funtion   */
void COMInit(serCOM,eBaudrate);                       /*UART init                     */
void COMInterrupt(serCOM,FunctionalState);            /*UART interrupt enable/disable */
int UART_printf(USART_TypeDef * ,char * );            /* UART print string*/
int UART_putc(USART_TypeDef * ,int );                 /* UART putc*/
